package com.mybatisx.mybatisplus.aop;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.mybatisx.mybatisplus.entity.User;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author wuyue
 * @date 2020/11/30 17:02
 */
@Service
public class TokenService {

    /**
     * 功能描述: <br>
     * 〈获取token时间〉
     * @Param: [userVo]
     * @Return: java.lang.String
     * @Author: wuyue
     * @Date: 2020/11/30 17:09
     */
    public String getToken(User user) {
        String token="";
        token= JWT.create()
                .withIssuedAt(new Date())
                .withExpiresAt(new Date(System.currentTimeMillis() + 60L*1000L)) //60秒
                .withAudience(user.getId().toString())
                .sign(Algorithm.HMAC256(user.getPassword()));

        return token;
    }
}
